{$layout "layout_popup"}

<h3>创建策略</h3>
<form class="ui form" data-tea-action="$" data-tea-success="success">
    <csrf-token></csrf-token>
    <table class="ui table definition selectable">
        <tr>
            <td class="title">策略名称 *</td>
            <td>
                <input type="text" name="name" maxlength="50" ref="focus"/>
            </td>
        </tr>
        <tr>
            <td>存储类型 *</td>
            <td>
                <select class="ui dropdown auto-width" name="type" v-model="type">
                    <option value="">[选择类型]</option>
                    <option v-for="type in types" :value="type.code">{{type.name}}</option>
                </select>
            </td>
        </tr>

        <!-- 文件 -->
        <tbody v-show="type == 'file'">
            <tr>
                <td>日志文件路径 *</td>
                <td>
                    <input type="text" name="filePath"/>
                    <p class="comment">
                        存储日志的文件路径，文件名中支持变量：
                        <span class="ui label tiny">年：${year}</span>
                        <span class="ui label tiny">月：${month}</span>
                        <span class="ui label tiny">周：${week}</span>
                        <span class="ui label tiny">日：${day}</span>
                        <span class="ui label tiny">时：${hour}</span>
                        <span class="ui label tiny">分：${minute}</span>
                        <span class="ui label tiny">秒：${second}</span>
                        <span class="ui label tiny">年月日：${date}</span>，比如<span class="ui label tiny">/var/log/web-access-${date}.log</span>，此文件会在API节点上写入。
                    </p>
                </td>
            </tr>
            <tr>
                <td>是否自动创建目录</td>
                <td>
                    <div class="ui checkbox">
                        <input type="checkbox" name="fileAutoCreate" value="1" checked="checked"/>
                        <label></label>
                    </div>
                    <p class="comment">选中后，如果文件目录不存在时可以自动创建。</p>
                </td>
            </tr>
        </tbody>

        <!-- Elastic Search -->
        <tbody v-show="type == 'es'">
            <tr>
                <td>Endpoint *</td>
                <td>
                    <input type="text" name="esEndpoint"/>
                    <p class="comment">ES HTTP接口地址，类似于192.168.1.100:9200，需要能够被API节点访问。</p>
                </td>
            </tr>
            <tr>
                <td>Index *</td>
                <td>
                    <input type="text" name="esIndex"/>
                    <p class="comment">Index名称，支持变量：
                        <span class="ui label tiny">年：${year}</span>
                        <span class="ui label tiny">月：${month}</span>
                        <span class="ui label tiny">周：${week}</span>
                        <span class="ui label tiny">日：${day}</span>
                        <span class="ui label tiny">时：${hour}</span>
                        <span class="ui label tiny">分：${minute}</span>
                        <span class="ui label tiny">秒：${second}</span>
                        <span class="ui label tiny">年月日：${date}</span></p>
                </td>
            </tr>
            <tr>
                <td>Mapping Type *</td>
                <td>
                    <input type="text" name="esMappingType"/>
                    <p class="comment">Mapping名称，支持变量：
                        <span class="ui label tiny">年：${year}</span>
                        <span class="ui label tiny">月：${month}</span>
                        <span class="ui label tiny">周：${week}</span>
                        <span class="ui label tiny">日：${day}</span>
                        <span class="ui label tiny">时：${hour}</span>
                        <span class="ui label tiny">分：${minute}</span>
                        <span class="ui label tiny">秒：${second}</span>
                        <span class="ui label tiny">年月日：${date}</span></p>
                </td>
            </tr>
            <tr>
                <td>认证用户名</td>
                <td>
                    <input type="text" name="esUsername"/>
                    <p class="comment">配置了认证后才需要填写。</p>
                </td>
            </tr>
            <tr>
                <td>认证密码</td>
                <td>
                    <input type="text" name="esPassword"/>
                    <p class="comment">配置了认证后才需要填写。</p>
                </td>
            </tr>
        </tbody>

        <!-- TCP Socket -->
        <tbody v-show="type == 'tcp'">
            <tr>
                <td>网络协议 *</td>
                <td>
                    <select name="tcpNetwork" class="ui dropdown" style="width:10em">
                        <option value="tcp">TCP</option>
                        <option value="unix">Unix Socket</option>
                    </select>
                </td>
            </tr>
            <tr>
                <td>网络地址 *</td>
                <td>
                    <input type="text" name="tcpAddr"/>
                    <p class="comment">接收日志的网络地址，需要能够被API节点访问。</p>
                </td>
            </tr>
        </tbody>

        <!-- Syslog -->
        <tbody v-show="type == 'syslog'">
        <tr>
            <td>网络协议</td>
            <td>
                <select class="ui dropdown" name="syslogProtocol" v-model="syslogProtocol" style="width:10em">
                    <option value="none">[无]</option>
                    <option value="tcp">TCP</option>
                    <option value="udp">UDP</option>
                    <option value="socket">Unix Socket</option>
                </select>
            </td>
        </tr>

        <tr v-if="syslogProtocol == 'tcp' || syslogProtocol == 'udp'">
            <td>网络地址 *</td>
            <td>
                <input type="text" name="syslogServerAddr"/>
                <p class="comment">IP地址或主机名，不包括端口，需要能够被API节点访问。</p>
            </td>
        </tr>
        <tr v-if="syslogProtocol == 'tcp' || syslogProtocol == 'udp'">
            <td>端口</td>
            <td>
                <input type="text" name="syslogServerPort"/>
            </td>
        </tr>

        <tr v-if="syslogProtocol == 'socket'">
            <td>Socket路径 *</td>
            <td>
                <input type="text" name="syslogSocket"/>
                <p class="comment">需要能够被API节点访问。</p>
            </td>
        </tr>

        <tr>
            <td>标签<em>(Tag)</em></td>
            <td>
                <input type="text" name="syslogTag"/>
                <p class="comment">选填项。</p>
            </td>
        </tr>
        <tr>
            <td>优先级<em>(Priority)</em></td>
            <td>
                <select class="ui dropdown" name="syslogPriority" style="width:10em">
                    <option v-for="priority in syslogPriorities" :value="priority.value">{{priority.name}}</option>
                </select>
                <p class="comment">选填项。</p>
            </td>
        </tr>
        </tbody>

        <!-- 命令行输入流 -->
        <tbody v-show="type == 'command'">
            <tr>
                <td>可执行文件 *</td>
                <td>
                    <input type="text" name="commandCommand"/>
                    <p class="comment">不带参数的可执行文件地址，此命令可执行文件需要部署在API节点上。</p>
                </td>
            </tr>
            <tr>
                <td>参数</td>
                <td>
                    <input type="text" name="commandArgs"/>
                    <p class="comment">执行命令需要的参数</p>
                </td>
            </tr>
            <tr>
                <td>工作目录</td>
                <td>
                    <input type="text" name="commandDir"/>
                    <p class="comment">命令执行所在的工作目录</p>
                </td>
            </tr>
        </tbody>

        <tr>
            <td>是否公用</td>
            <td>
                <checkbox name="isPublic" value="1"></checkbox>
                <p class="comment"><span class="red">选中后表示自动将此策略应用于所有集群，同时只会有一个公用策略。</span></p>
            </td>
        </tr>
    </table>
    <submit-btn></submit-btn>
</form>